﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BusinessLayer.Model.Repositories.Abstract;
using BusinessLayer.Model.Entities;
using System.Data.Linq;
using BusinessLayer.Model.Services.Abstract;
using DataAccess.Services;


namespace DataAccess.Repositories
{
    public class PictureRepository : IPictureRepository
    {
        private readonly IntecDataContext _db = new IntecDataContext();
        private readonly Table<Picture> _picturesTable;

        public PictureRepository()
        {
           _picturesTable = _db.GetTable<Picture>();
        }

        #region IPictureRepository Members

        public Picture FetchByID(Guid pictureID)
        {
            return (from p in _picturesTable
                    where p.PictureID == pictureID
                    select p).First();            
        }

        public IEnumerable<Picture> FetchAll()
        {
            return _picturesTable.AsEnumerable();
        }

        public void Add(Picture picture)
        {
            _picturesTable.InsertOnSubmit(picture);
        }

        public void Update(Picture picture)
        {
            throw new NotImplementedException();
        }

        public void Remove(Picture picture)
        {
            _picturesTable.DeleteOnSubmit(picture);
        }

        public void SubmitChanges()
        {
            _db.SubmitChanges();
        }

        #endregion
    }
}
